import { Application } from 'egg'
import { Models } from 'sequelize'

export default (app: Application) => {
  const { UUID, UUIDV4, STRING, JSONB } = app.Sequelize.DataTypes
  /** 系统设置和用户设置 */
  const model = app.model.define('settings', {
    id: { type: UUID, defaultValue: UUIDV4, primaryKey: true },
    /** 设置名 */
    name: STRING,
    /** 中文名 */
    title: STRING,
    /** 设置值 */
    value: JSONB,
    /** 设置说明 */
    desc: STRING,
  })

  model.associate = (models: Models) => {
    model.belongsTo(app.model['User'], { onDelete: 'CASCADE' })
  }

  return model
}
